  <template>
  <div id="album">
    <div class="album-bg"></div>
    <div class="album-slide">
      <div class="album-slide">
        <div class="album-img">
          <v-upload v-model="userAvator" :isAudio="false" :pic-width="200" :pic-height="200"
                    needSignature url="/signature?type=image">
          </v-upload>
          <div class="font_Avator">
            <span>更换头像</span>
          </div>
        </div>

        <div class="album-info">
          <ul>
            <li>
              <svg-icon :icon-class="!sex?'nv':'nan_1'" size="40"></svg-icon>
              <span>{{username}}</span>
              <svg-icon icon-class="dangao" size="40"></svg-icon>
              <span>{{createTime}}</span>
            </li>
            <li>
              <svg-icon icon-class="shouji" size="40"></svg-icon>
              <span>{{phone}}</span>
              <svg-icon icon-class="diqu" size="40"></svg-icon>
              <span>{{location}}</span>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="album-content">

      <div class="album-title">个性签名: {{mySignature}}</div>
      <div class="songs-body">
        <div class="mysong_tab">
          <v-tabs slider-color="black" style="padding-top: 20px">
            <label>我的收藏</label>
            <v-tab @click="changeView('AlbumContent')" style="margin-left: 100px;">
              <svg-icon icon-class="gequ" size="30"></svg-icon>
              <span>歌曲</span>
            </v-tab>
            <v-tab @click="changeView('ContentList')" style="margin-left: 100px;">
              <svg-icon icon-class="shoucangdaogedan" size="40"></svg-icon>
              <span>歌单</span>
            </v-tab>
            <v-tab @click="changeView('uploadSongList')" style="margin-left: 100px;">
              <svg-icon icon-class="uploadList" size="40"></svg-icon>
              <span>我的上传</span>
            </v-tab>
          </v-tabs>
        </div>
        <div v-if="selectView===0" class="content">
          <album-content :songList="collecSongs"></album-content>
        </div>
        <div v-if="selectView===1" class="content">
          <hr>
          <content-list :contentList="collectLists">

          </content-list>
        </div>
        <div v-if="selectView===2" class="content">
          <hr>
          <upload-list :songList="uploadSongLists">

          </upload-list>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import {mixin} from '../mixins'
import { mapGetters } from 'vuex'
import AlbumContent from '../components/AlbumContent'
import UploadList from '../components/UploadList'
import ContentList from '../components/ContentList'

export default {
  name: 'my-song',
  data () {
    return {
      userSex: '1',
      collection: [], // 存放收藏的歌曲ID
      collectList: [], // 收藏的歌曲
      currentView: 'AlbumContent',
      userAvator: '',
      isAlbumContent: true,
      selectView: 0,
      collecSongs: [],
      collectLists: [],
      uploadSongLists: []
    }
  },
  watch: {
    userAvator: function () {
      this.updateUser()
    }
  },
  created() {
    this.goVerify()
    this.getCollectSong()
    this.getCollectLists()
  },
  mounted() {
    this.userAvator = this.avator
  },
  computed: {
    ...mapGetters([
      'userId',
      'id',
      'listOfSongs', // 存放的音乐

      'activeName',

      'avator',
      'username',
      'loginIn',
      'sex',
      'createTime',
      'mySignature',
      'phone',
      'location'
    ])
  },
  components: {
    AlbumContent,
    ContentList,
    UploadList
  },
  mounted () {
  },
  mixins: [mixin],
  methods: {
    updateUser () {
      const params = this.$qs.stringify({
        id: this.userId,
        avator: this.userAvator,
        mySignature: this.mySignature
      })
      axios.put(this.$store.state.HOST + '/user/save',params).then(resp =>{
        console.log(resp.data)
        this.userAvator = resp.data.avator
        this.copyMsg(resp.data)
      })
    },
    changeView(currentView) {
      if (currentView === 'AlbumContent') {
        this.isAlbumContent = true
        this.selectView = 0
        this.getCollectSong()
        console.log(this.selectView)
      }else if(currentView === 'ContentList'){
        this.isAlbumContent = false
        this.selectView = 1
        this.getCollectLists()
        console.log(this.selectView)
      } else {
        this.selectView = 2
        this.getuploadSongLists()
        console.log(this.selectView)
      }

    },
    getuserSex (sex) {
      if (sex === 0) {
        this.userSex = '女'
      } else if (sex === 1) {
        this.userSex = '男'
      }
    },
    // 获取收藏的歌曲
    getCollectSong() {
      axios.get(this.$store.state.HOST+ "/collect/collectSongs?userId="+this.userId).then(resp=>{
        this.collecSongs = resp.data
      }).catch(()=>{
        this.collecSongs = []
      })
    },
    getCollectLists() {
      axios.get(this.$store.state.HOST+ "/collect/collectLists?userId="+this.userId).then(resp=>{
        this.collectLists = resp.data
      }).catch(()=>{
        this.collectLists = []
      })
    },
    getuploadSongLists() {
      axios.get(this.$store.state.HOST+ "/user/upload/list?userId="+this.userId).then(resp=>{
        this.uploadSongLists = resp.data
      }).catch(()=>{
        this.uploadSongLists = []
      })
    },
    goVerify () {
      axios.post(this.$store.state.HOST + "/verify").then(resp=>{
        console.log(resp.data)
        this.copyMsg(resp.data)
        this.userAvator = this.avator
      }).catch(()=>{
        let user = {
          id: '',
          username: '',
          avator: '',
          sex: 1,
          mySignature:'',
          phone:'',
          location: '',
          createTime:''
        }
        this.copyMsg(user)
        this.$store.commit('setLoginIn', false)
        window.sessionStorage.setItem('loginIn', JSON.stringify(false))
        this.$notify({
          title: '登录失效或你还没登录',
          type: 'warning'
        })
        // window.location.href("http://120.79.58.44:8082/")
        window.location.href("http://localhost:8082/")
      })
    }
  }
}
</script>

<style scoped>
  .content {
    background-color: white;
    border-radius: 12px;
    padding: 20px 40px;
    min-width: 700px;
  }
  .font_Avator {
    width: 100%;
    height: 50px;
    font-size: 1.8em;
    position: absolute;
    color: white;
    background: black;
    opacity:0.4;
    bottom: 0px;
    text-align: center;
  }
  .font_Avator span {
  }
  /*歌单背景*/
  .album-bg {
    width: 100%;
    height: 180px;
    background-color: #93d2f8;
  }
  /*歌单左侧*/
  .album-slide {
    float: left;
    width: 100%;
  }
  /*歌单图像*/
  .album-img {
    height: 200px;
    width: 200px;
    display: inline-block;
    position: relative;
    top:-100px;
    left: 40%;
    border-radius: 50%;
    overflow: hidden;
    border: 5px solid white;
  }
  .album-img img {
    width: 100%;
  }
  /*歌单信息*/
  .album-info {
    color: black;
    width: 100%;
    font-size: 20px;
    font-weight: 500;
    margin-top: -100px;
    margin-left: 30%;
    padding: 30px 30px;
  }
  .album-info li {
    width: 100%;
    line-height: 40px;
  }
  .album-info ul li span {
    margin-left: 40px;
    display: inline-block;
    width: 200px;
  }
  /*歌单内容*/
  .album-content{
    margin-left: 7%;
    padding: 40px 100px;
    width: 75%;
  }
  /*歌单题目*/
  .album-title {
    font-size: 30px;
    font-weight: 600;
    margin-left: 10%;
  }
  .songs-body {
    margin-top: 50px;
  }

  .mysong_tab {
    height: 80px;
    background-color: white;
    position: relative;
    bottom: -10px;
  }
  .mysong_tab label{
    display: inline-block;
    font-size: 1.5em;
    font-weight: 600;
    margin-left: 50px;
    margin-top: 10px;
  }
  .mysong_tab span {
    font-size: 1.4em;
    margin-left: 10px;

  }
</style>
